package com.crm.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Transaction;

import com.crm.dao.base.BaseHibernateDAO;
import com.crm.po.Fp1;


public class Fp1DAO extends BaseHibernateDAO {

	private static Logger logger = Logger.getLogger(Fp1DAO.class);

	public void save(Fp1 fp1) {
		if(fp1.getRecid() == null || fp1.getRecid().trim().length() == 0){
			fp1.setRecid(this.getUUID());
		}
		Transaction transaction = getSession().beginTransaction();
		try {
			this.getSession().save(fp1);
			transaction.commit();
		} catch (RuntimeException e) {
			transaction.rollback();
			logger.error(e);
		} finally {
			this.closeSession();	
		}
	}

	public void saveOrUpdate(Fp1 fp1) {
		if(fp1.getRecid() == null || fp1.getRecid().trim().length() == 0){
			fp1.setRecid(this.getUUID());
		}
		Transaction transaction = getSession().beginTransaction();
		try {						
			this.getSession().saveOrUpdate(fp1);
			transaction.commit();
		} catch (RuntimeException e) {
			transaction.rollback();
			logger.error(e);
		} finally {
			this.closeSession();	
		}
	}
	
	public void delete(Fp1 fp1) {
		Transaction transaction = getSession().beginTransaction();
		try {
			this.getSession().delete(fp1);
			transaction.commit();
		} catch (RuntimeException e) {
			transaction.rollback();
			logger.error(e);
		} finally {
			this.closeSession();	
		}
	}

	public Fp1 findById(String id) {
		Fp1 fp1 = null;
		try {
			fp1 = (Fp1) this.getSession().get(Fp1.class, id);
		} catch (RuntimeException e) {
			logger.error(e);
		} finally {
			this.closeSession();	
		}
		return fp1;
	}
	
	@SuppressWarnings("unchecked")
	public List<Fp1> fp1List(String hql) {
		return (List<Fp1>) findList(hql);
	}
	
	@SuppressWarnings("unchecked")
	public List<Fp1> fp1ListPage(String hql, int start, int limit) {
		return (List<Fp1>) findListPage(hql, start, limit);
	}

}